<html>
  <head>
    <title>iTunes Web Service Test Page</title>
  </head>
  <script src="scripts/json2.js" type="text/javascript"></script>
  <script src="scripts/itunes.js" type="text/javascript"></script>
  <script type="text/javascript">
    var itunes = new iTunesWebController();

    var callback = function(result) {
      var msg = '';
      if (result) {
        msg = JSON.stringify(result, null, 1);
      }
      document.getElementById('message').innerHTML = msg;
    }

    var errorCallback = function(result) {
      var msg = 'ERROR';
      if (result) {
        msg = msg + ': ' + JSON.stringify(result, null, '&nbsp;');
      }
      document.getElementById('message').innerHTML = msg;
    }

    function getCurrentTrack(){
      itunes.getCurrentTrack(callback, errorCallback);
      return false;
    }

    function getPlayerPosition(){
      itunes.getPlayerPosition(callback, errorCallback);
      return false;
    }

    function getPlayerState(){
      itunes.getPlayerState(callback, errorCallback);
      return false;
    }

    function getPlaylist(){
      var sourceId = document.getElementById('getPlaylist_sourceId').value;
      var playlistId = document.getElementById('getPlaylist_playlistId').value;
      itunes.getPlaylist(sourceId, playlistId, callback, errorCallback);
      return false;
    }

    function getPlaylists(){
      itunes.getPlaylists(callback, errorCallback);
      return false;
    }

    function getTrack(){
      var sourceId = document.getElementById('getTrack_sourceId').value;
      var playlistId = document.getElementById('getTrack_playlistId').value;
      var trackId = document.getElementById('getTrack_trackId').value;
      var databaseId = document.getElementById('getTrack_databaseId').value;
      itunes.getTrack(sourceId, playlistId, trackId, databaseId, callback, errorCallback);
      return false;
    }

    function getTracksInPlaylist(){
      var sourceId = document.getElementById('getTracksInPlaylist_sourceId').value;
      var playlistId = document.getElementById('getTracksInPlaylist_playlistId').value;
      itunes.getTracksInPlaylist(sourceId, playlistId, callback, errorCallback);
      return false;
    }

    function getVolume() {
      itunes.getVolume(callback, errorCallback);
      return false;
    }

    function isMute() {
      itunes.isMute(callback, errorCallback);
      return false;
    }

    function nextTrack() {
      itunes.nextTrack(callback, errorCallback);
      return false;
    }

    function pause() {
      itunes.pause(callback, errorCallback);
      return false;
    }

    function play() {
      itunes.play(callback, errorCallback);
      return false;
    }

    function playPause() {
      itunes.playPause(callback, errorCallback);
      return false;
    }

    function previousTrack() {
      itunes.previousTrack(callback, errorCallback);
      return false;
    }

    function playlistSearch() {
      var term = document.getElementById('search_term').value;
      var field = document.getElementById('search_field').options[document.getElementById('search_field').selectedIndex].value;
      itunes.search(term, field, callback, errorCallback);
      return false;
    }

    function setMute(){
      itunes.setMute(callback, errorCallback);
      return false;
    }

    function stop() {
      itunes.stop(callback, errorCallback);
      return false;
    }
  </script>
  <body>
    <table border="0" width="90%" cellpadding="8" cellspacing="0">
    <tr><td valign="top" width="200">
      <ul>
        <li><a href="#" onclick="play();">Play</a></li>
        <li><a href="#" onclick="pause();">Pause</a></li>
        <li><a href="#" onclick="playPause();">Play / Pause</a></li>
        <li><a href="#" onclick="stop();">Stop</a></li>
        <li><a href="#" onclick="getVolume();">Get Volume</a></li>
        <li><a href="#" onclick="isMute();">Is Mute?</a></li>
        <li><a href="#" onclick="nextTrack();">Next Track</a></li>
        <li><a href="#" onclick="previousTrack();">Previous Track</a></li>
        <li><a href="#" onclick="getCurrentTrack();">Get Current Track</a></li>
        <li><a href="#" onclick="getPlayerPosition();">Get Player Position</a></li>
        <li><a href="#" onclick="getPlayerState();">Get Player State</a></li>
        <li><a href="#" onclick="getPlaylists();">Get Playlists</a></li>
        <li><a href="#" onclick="getPlaylist();">Get Playlist</a><br />
            source id: <input type="text" id="getPlaylist_sourceId" size="4" /><br />
            playlist id: <input type="text" id="getPlaylist_playlistId" size="4" />
        </li>
        <li><a href="#" onclick="getTracksInPlaylist();">Get Tracks In Playlist</a><br />
            source id: <input type="text" id="getTracksInPlaylist_sourceId" size="4" /><br />
            playlist id: <input type="text" id="getTracksInPlaylist_playlistId" size="4" />
        </li>
        <li><a href="#" onclick="getTrack();">Get Track</a><br />
            source id: <input type="text" id="getTrack_sourceId" size="4" /><br />
            playlist id: <input type="text" id="getTrack_playlistId" size="4" /><br />
            track id: <input type="text" id="getTrack_trackId" size="4" /><br />
            database id: <input type="text" id="getTrack_databaseId" size="4" />
        </li>
        <li><a href="#" onclick="playlistSearch();">Search</a><br />
            term: <input type="text" id="search_term" /><br />
            field: <select id="search_field">
                     <option value="0">All</option>
                     <option value="1">Visible</option>
                     <option value="2">Artists</option>
                     <option value="3">Album</option>
                     <option value="4">Composers</option>
                     <option value="5">Song Name</option>
                   </select>
        </li>
      </ul>
    </td><td valign="top">
      <div id="message"></div>
    </td></tr>
    </table>
  </body>
</html>